package com.asset.dispoal.companyMenu.service.command;

import com.asset.dispoal.companyMenu.domain.db.entity.CompanyMenu;
import com.asset.dispoal.companyMenu.domain.db.mapper.CompanyMenuMapper;
import com.asset.dispoal.companyMenu.dto.CompanyMenuRequest;
import com.asset.dispoal.companyMenu.service.converter.CompanyMenuModifyConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @author qr
 * @date 2022/3/28$
 */
@Component
public class CompanyMenuModifyCommand implements BaseCommand<CompanyMenuRequest, Result> {

    @Autowired
    CompanyMenuMapper companyMenuMapper;

    @Override
    @Transactional
    public Result execute(CompanyMenuRequest request) {
        companyMenuMapper.delete(request.getCompanyId());
        CompanyMenu companyMenu = CompanyMenuModifyConverter.INSTANCE.reqToDo(request);
        companyMenuMapper.insert(companyMenu);
        return Result.ok();
    }
}
